Skip to content

Allow CameraRoll to export videos#7988

Closed
corbt wants to merge 1 commit intofacebook:masterfrom
corbt:cameraroll-videos
Closed

Allow CameraRoll to export videos#7988
corbt wants to merge 1 commit intofacebook:masterfrom
corbt:cameraroll-videos

Conversation

@corbt
Copy link
Copy Markdown
Contributor

@corbt corbt commented Jun 7, 2016

This PR adds the ability to export videos to the CameraRoll on both Android and iOS (previously only photos were possible, at least on iOS). The API has changed as follows:

// old
saveImageWithTag(tag: string): Promise<string>

// new
saveToCameraRoll(tag: string, type?: 'photo' | 'video'): Promise<string>

if no type parameter is passed, video is inferred if the tag ends with ".mov" or ".mp4", otherwise photo is assumed.

I've left in the saveImageWithTag method for now with a deprecation warning.

Test plan (required)

I created the following very simple app to test exporting photos and videos to the CameraRoll, and ran it on both iOS and Android. The functionality works as intended on both platforms.

// index.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  CameraRoll,
} from 'react-native';
import FS from 'react-native-fs';

const vidPath = FS.DocumentDirectoryPath + '/vid.mp4';
const picPath = FS.DocumentDirectoryPath + '/pic.jpg';

class SaveToCameraRoll extends Component {
  componentDidMount() {
    FS.downloadFile({ fromUrl: 'https://s3.amazonaws.com/assets.emberall.com/TMP/pic.jpg', toFile: picPath })
    FS.downloadFile({ fromUrl: 'https://s3.amazonaws.com/assets.emberall.com/TMP/vid.mp4', toFile: vidPath })
  }
  _exportPhoto = () => {
    console.log('EXPORTING PHOTO');
    CameraRoll.saveToCameraRoll(picPath);
  };

  _exportVideo = () => {
    console.log('EXPORTING VIDEO');
    CameraRoll.saveToCameraRoll(vidPath);
  };

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Test Camera Roll
        </Text>
        <Text style={styles.instructions} onPress={this._exportPhoto}>
          Export Photo
        </Text>
        <Text style={styles.instructions} onPress={this._exportVideo}>
          Export Video
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('SaveToCameraRoll', () => SaveToCameraRoll);

@ghost
Copy link
Copy Markdown

ghost commented Jun 7, 2016

By analyzing the blame information on this pull request, we identified @bestander and @dmmiller to be potential reviewers.

@ghost ghost added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jun 7, 2016
@nicklockwood
Copy link
Copy Markdown
Contributor

@facebook-github-bot shipit

@ghost ghost added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Jun 7, 2016
@ghost
Copy link
Copy Markdown

ghost commented Jun 7, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in 7357ccc Jun 7, 2016
@bestander
Copy link
Copy Markdown
Contributor

Note that this commit broke website generation, I'll see if there is a quick fix

bestander added a commit to bestander/react-native that referenced this pull request Jun 8, 2016
Fixes whate was broken in facebook#7988

Website generation does not understand Promise<*>.

Test Plan:
- cd website
- node server/server.js
- navigate to http://localhost:8079/react-native/docs/cameraroll.html
ghost pushed a commit that referenced this pull request Jun 8, 2016
Summary:
Fixes whate was broken in #7988

Website generation does not understand Promise<*>.
Closes #8002

Differential Revision: D3404468

Pulled By: avaly

fbshipit-source-id: 9070ce038431795b0195f9eb0366aab5f3fb4cb0
bartolkaruza pushed a commit to bartolkaruza/react-native-cameraroll that referenced this pull request Feb 23, 2019
Summary:
This PR adds the ability to export videos to the CameraRoll on both Android and iOS (previously only photos were possible, at least on iOS). The API has changed as follows:

```
// old
saveImageWithTag(tag: string): Promise<string>

// new
saveToCameraRoll(tag: string, type?: 'photo' | 'video'): Promise<string>
```

if no `type` parameter is passed, `video` is inferred if the tag ends with ".mov" or ".mp4", otherwise `photo` is assumed.

I've left in the `saveImageWithTag` method for now with a deprecation warning.

**Test plan (required)**

I created the following very simple app to test exporting photos and videos to the CameraRoll, and ran it on both iOS and Android. The functionality works as intended on both platforms.

```js
// index.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  CameraRoll,
} from 'react-native';
import FS fro
Closes facebook/react-native#7988

Differential Revision: D3401251

Pulled By: nicklockwood

fbshipit-source-id: af3fc24e6fa5b84ac377e9173f3709c6f9795f20
bartolkaruza pushed a commit to bartolkaruza/react-native-cameraroll that referenced this pull request Feb 24, 2019
Summary:
This PR adds the ability to export videos to the CameraRoll on both Android and iOS (previously only photos were possible, at least on iOS). The API has changed as follows:

```
// old
saveImageWithTag(tag: string): Promise<string>

// new
saveToCameraRoll(tag: string, type?: 'photo' | 'video'): Promise<string>
```

if no `type` parameter is passed, `video` is inferred if the tag ends with ".mov" or ".mp4", otherwise `photo` is assumed.

I've left in the `saveImageWithTag` method for now with a deprecation warning.

**Test plan (required)**

I created the following very simple app to test exporting photos and videos to the CameraRoll, and ran it on both iOS and Android. The functionality works as intended on both platforms.

```js
// index.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  CameraRoll,
} from 'react-native';
import FS fro
Closes facebook/react-native#7988

Differential Revision: D3401251

Pulled By: nicklockwood

fbshipit-source-id: af3fc24e6fa5b84ac377e9173f3709c6f9795f20
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants